READ ME file for replicating Gonzalez & Haas: "The Neural Mechanisms of Race Priming in American Politics"

Data processing and analysis for this paper involves several steps, including data processing and analysis for the survey and task data as well as data processing and analysis for the fMRI data. 



#####SURVEY/TASK DATA & ANALYSIS#####

The data and scripts for the analysis of survey and task data are contained in the "DataScripts-SurveyTask" folder. Using R, we created a clean data set from the raw Qualtrics survey data to look at between-subjects descriptive statistics (e.g., demographics, attitudes toward race-based policies). The raw task data consisted of a separate .csv file for each participant. We merged all participants' task data together using Python to create a data set where rows are at the participant-trial level. Then, in R, we performed additional data cleaning and recoding on the merged data set before merging the task data with the survey data. Ultimately, we produced a "long" data set with participant-trial as the unit of analysis and including survey variables as between-subjects variables.

That folder contains the following: 
- folder "Task_data": includes task data for each participant, as well as Python script used to merge files, raw merged file ("aggregate_Task_raw.csv"), and clean merged file after manually re-formatting data set to be ready for analysis in R ("aggregate_Task_R.csv"). 

- Diss_NSF_Post-Scan (2): Word document with outputted Qualtrics survey

- RacePriming_SurveyTask_clean-merge.R: R script for cleaning and merging survey and task data

- Diss_NSF_PostScan_raw.csv: Raw Qualtrics survey data

- Diss_NSF_PostScan_R.csv: Qualtrics survey data formatted for data analysis

- Diss_NSF_PostScan_R_2.csv: Qualtrics survey data written out from R including new variables (for purposes of reshaping into "long" format)

- Diss_NSF_PostScan_Rx.csv: Diss_NSF_PostScan_R_2 but with new blank rows from 0 to 159 (used solely to reshape data into long format with 160 rows per participant).

- Diss_NSF_PythonLong_temp.csv: Long version of task data (intermediate data set between reshaping and merging with survey data)

- Diss_NSF_QualLong_temp.csv: Long version of survey data (intermediate data set between reshaping and merging with task data)

- MRIDiss_combined_wide.csv: Final WIDE data set (including survey variables and summary task data variables at participant-level)

- MRIDiss_combined_wideX.csv: MRIDiss_combined_wide.csv but with new blank rows from 0 to 159 (used solely to reshape data into long format with 160 rows per participant)

- Diss_NSF_long_combined.csv: Final LONG data set (including survey variables and task variables at participant-trial level)

- RacePriming_behavioral_MLM-2023.R: R script for analyzing survey/task data


By following through the RacePriming_SurveyTask_clean-merge.R script, you should be able to recreate the data set including all survey and task data used for analyses of survey and task data performed in the RacePriming_behavioral_MLM-2023.R script. 


#####MRI DATA & ANALYSIS#####

The MRI data consist originally in their raw form as a large set of raw image files generated from the Siemens system during scanning. These include one "MPRage" structural image file (which is used to create a baseline, high-definition image of each participant's brain) and functional images (which are used to identify BOLD activity during the 4 blocks of the task). 

The data files necessary to go from raw to processed/analysed data are all available. The raw data are in folders with the prefix, "mprage-bold." There is one folder per participant. Each folder contains a raw, unprocessed mprage file (without skull stripping - see below), a processed, skull stripped mprage file (entitled just "mprage"), and BOLD files for each of the 4 blocks of the experiment. 

The steps to analyzing the MRI data include: 1) pre-processing, 2) level 1 analyses, 3) level 2 analyses, and 4) level 3 analyses. We have one additional set of analyses looking at contrasts across levels of CBPE as well. 

Pre-processing involves cleaning the raw image files for analysis. Level 1 involves analyzing BOLD activity within each participant for each block (out of 4) separately. Level 2 involves a combined analysis of Conscious versus Nonconscious blocks for each participant separately. Level 3 involves combined analyses of Conscious versus Nonconscious blocks across all participants together using ROI masks to focus on each of our main brain regions of interest. Finally, the CBPE analses involve a Level 3 analysis but with the additional contrast of CBPE scores. 

For the MRI analyses, you will need two free programs. One is called FSL,  (https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FslInstallation/MacOsX), which is only available for Mac and Linux. The other is MRIcroGL (https://www.nitrc.org/projects/mricrogl). 

The pre-processing involves taking the MPRage structural image file for each participant (the raw file with a long title that includes skull - not the file simply entitled "mprage") and making sure it is ready for analysis using MRIcroGL and FSL. First, we converted the images to the proper format for analysis in FSL and processing in MRIcroGL ("nii.gz"). The files available on dataverse are already converted, but if you were starting from scratch, the files would need to be converted from DICOM to NIfTI (Import -> Convert DICOM to NIfTI in MRIcroGL will allow you to select the entire folder for each participant and convert all files one-at-a-time). Then, open up FSL. To open FSL, type "fsl" into Terminal on your computer (we used MAC for our analyses and so those are the instructions we provide). FSL should open (XQuartz will open the FSL GUI). In FSL, we performed "skull stripping" (also called Brain Extraction), which involves removing the skull from the MPRage images for each participant so it is only brain in each image. This creates the skull stripped mprage files (entitled just "mprage") available on dataverse for each participant, but if you were to recreate the process, you would open FSL and click "BET - Brain Extraction Tool." Then, choose the raw mprage fie as the "Input image" in your directory. The "Output image" will automatically be created in that same directory with the suffix, "_brain," at the end. We used the default settings for each participant.  

*****
NOTES ABOUT USING TERMINAL FOR SUBSEQUENT ANALYSES: In FSL, you can point-and-click to manually recreate each analysis, but that would be very time intensive and so we provide the batch scripts in order for you to have your computer automatically run each FSL script consecutively. We explain the batch scripts below, but note that to run a batch script, you need to run some commands in Terminal. First, make sure the batch script is saved as a ".sh" file (our files on dataverse should already be saved as such). Then, to run a batch script, type "sh ./filename.sh". the "./" just means to indicate your current directory. Sometimes, you will get an error saying that you need to give the file "execute permissions." If that happens, use "chmod u+x scriptname" to give the batch script execute permissions and then try running it again.
	- NOTE on using Terminal for MAC: To check your working directory, type "pwd". Then, you can set your working directory using the "cd" command. For example, "cd Users/fgonzo/Desktop". You will need to make sure your working directory is where your batch scripts are saved. You can type "ls" to see all the files within your working directory to make sure you are working in the right folder. 
*****

We created "feat" files (which are FSL scripts ending in ".fsf") for all analyses, which can be run through batch scripts in terminal. The batch script for running the first- and second-level feat files is called "batch_supportBW_first-second-levels.sh" The first feat files are all commended out. By un-commenting all the level 1 feat commands first (all lines ending with "design1" through "design4") and running the file in terminal, FSL will perform all level 1 analyses. Then, by commenting all lines for level 2 (lines ending with "second_level"), FSL will run all level 2 analyses. Each of these analyses will take approximately 15 minutes to run.

***Importantly, you will need to edit *each* .fsf file and batch script to make sure to change each filepath to the filepath where your files are stored in both the batch scripts AND in the individual .fsf files (in each .fsf file, if you search for "/Volumes/gonzalez/", you should find every reference to a directory that needs to be changed). There is one filepath in the .fsf files that does not need to be changed: "/usr/local/fsl/data/standard/MNI152_T1_2mm_brain" --- this file should exist on your local computer when you download FSL.

Running "batch_supportBW_first-second-levels.sh" script (and thus the .fsf files referenced in these scripts) should create a series of folders in your working directory named "cope" followed by a number from 1 to 5. These files will be referenced in Level 3. 

Then, we have separate batch scripts for doing ROI analyses in level 3. The script named "batch_script-all-NoBW" will run the masked Level 3 ROI analyses as well as a whole brain unmasked analysis, which we include just for reference but is not used to test our hypotheses in the paper. Make sure that the folder entitled "masks" has been downloaded, is in your working directory, and is properly referenced in the .fsf files in terms of the folder each mask is in. Each of these analyses may take several hours to run. If you want to keep the analyses running overnight, you need to turn off the screensaver on your computer so that it does not go to sleep while the analysis is running.

Running these analyses will produce "featquery" folders in your working directory where the final results are included in an HTML file (which can be opened up in any browser) called "report." If you open the "report" file, it will show the results of the analysis in a table. The row of interest is the one entitled "thresh_zstat1." You will have two "cope" folders (and thus two "report" files - one in each folder) for each ROI analysis. "Cope3" contains the results for the "Nonconscious > Conscious" contrast (and so clusters of activation in Nonconscious relative to Conscious trials). "Cope4" contains the results for the "Conscious > Nonconscious" contrast (and so clusters of activation in Conscious relative to Nonconscious trials).

The same process is then used to produce the results for the CPBE contrasts, although now you can access both contrasts in one HTML report under "cope4". The "thresh_zstat3" row contains the results for the "> CPBE" contrast and "thresh_zstat2" row contains the results for the "< CPBE" contrast. The batch script for running the .fsf files for the CPBE analyses is entitled "batch_script-all-CPBE." This script will run the .fsf files with prefix "CPBE_all27_". Again, make sure to change the directory file paths in the batch script as well as the .fsf files. These analyses take approximately the same amount of time to run as the above, level 3 analyses. 


We have included on Dataverse the HTML report files that replicate all tables from the paper. 



#####FIGURE RE-CREATION#####

The figures illustrating the MRI results (Figures 2 & 3) were created using MRIcroGL. First, open MRIcroGL. Then, open a standard brain image (we used "MNI152_T1_2mm_brain.nii.gz", which can be found in the filepath: /usr/local/fsl/data/standard/. This brain image should automatically be available upon downloading fs. Then, find the folder with the results of the analyses you want to plot. Then, in the "cope" folder that you want (see above for which "cope" folders indicate which analyses), you should find a series of "nii.gz" files. Then, in MRIcroGL, select File -> Add Overlay, and select "thresh_zstat1.nii.gz" (or, again, "zstat2" or "zstat3" depending on the analysis you want to plot). This should add a layer to your image with the clusters of significant activation. You can change the color scheme for this layer by changing the color scheme option in the dropdown menu in MRIcroGL. Then, you can add another overlay the same way except selecting the "mask.nii.gz" file, which should be in the "featquery_" folder in the "cope" folder you are currently working from. You can adjust the color and opacity on this overlay as well. Type in the coordinate shown in each figure to display the exact cross-section shown in the figure. 

For example, to recreate Figure 2 ("BOLD Activation in dlPFC in Response to Conscious > Nonconscious Trials"), first open the "MNI152_T1_2mm_brain.nii.gz" file in the /usr/local/fsl/data/standard/ directory. Then, add an overlay with the significant activation clusters by clicking File -> Add Overlay and locating the results folder created from running that analysis, which will be called "NoBW_all27_ROIuncorr_dlpfc.gfeat" (unless you renamed it manually in the .fsf file). In that folder, click on "cope4" (because we are interested in the Conscious > Nonconscious contrast and open the "cope4.feat" folder. Then, select the "thresh_zstat1.nii.gz" file. Adjust the colors as you like (we used "8redyell") and type in the coordinates -44, 38, 18. Then, to add the ROI overlay, add Overlay again and from the "cope4.feat" folder, select "featquery_dlpfc" -> "mask.nii.gz". Adjust the color (we used "1red") and transparency accordingly. 

For Figure 3, the files are within the results folder for the CPBE analyses for ACC (top panel) and Insula (bottom panel). For both panels, use the "zstat3" files. 



